// ProxyBridge.ts
export class ProxyBridge {
  private listeners: Record<string, Function[]> = {};

  // 单例模式
  private static instance: ProxyBridge;
  public static getInstance(): ProxyBridge {
    if (!ProxyBridge.instance) {
      ProxyBridge.instance = new ProxyBridge();
    }
    return ProxyBridge.instance;
  }

  // 订阅事件
  on(event: string, callback: Function) {
    if (!this.listeners[event]) {
      this.listeners[event] = [];
    }
    this.listeners[event].push(callback);
  }

  // 触发事件
  emit(event: string, data?: any) {
    if (this.listeners[event]) {
      this.listeners[event].forEach((callback) => callback(data));
    }
  }
}

// 导出单例
export const proxyBridge = ProxyBridge.getInstance();